import requests
import pymysql

f=open("password.txt","r")
password=f.read()
f.close()
password=password.replace("\n","")
conn = pymysql.connect(host='localhost', user='root',
                       password=password, database='teamfight_wiki', port=3306)
cursor = conn.cursor()
base_url = "https://game.gtimg.cn/images/lol/act/img/tft/js/"
equip_url = base_url + "equip-2.js"
count = 0
response = requests.get(equip_url)
data = response.json()
equip_type={"1":"基础装备","2":"合成装备","3":"光明武器","4":"特殊装备","5":"转职纹章","6":"奥恩神器","7":"金鳞龙装备","8":"辅助装备"}
equips={}
for i in data["data"]:
    equips[i["equipId"]]=i["name"]
    if i["formula"]=="":
        continue
    name1,name2=i["formula"].split(",")
    sql = f"""select equip_id from equip where equip_name="{i["name"]}";"""
    cursor.execute(sql)
    result = cursor.fetchall()
    equip_id = result[0][0]
    sql = f"""select equip_id from equip where equip_name="{equips[name1]}";"""
    cursor.execute(sql)
    result = cursor.fetchall()
    equip_id1 = result[0][0]
    sql = f"""select equip_id from equip where equip_name="{equips[name2]}";"""
    cursor.execute(sql)
    result = cursor.fetchall()
    equip_id2 = result[0][0]
    sql = f"""insert into equip_synthesis values({equip_id},{equip_id1},{equip_id2})"""
    cursor.execute(sql)
conn.commit()
